<?php

use yii\grid\GridView;
use common\helpers\Html;
use yii\helpers\Url;
$this->title = '请假管理';
$this->params['breadcrumbs'][] = ['label' => $this->title];

?>

<div class="row">
    <div class="col-xs-12">
        <div class="box">
            <div class="box-header">
                <h3 class="box-title">
                    <?= $this->title; ?>
                    <small></small>
                </h3>
                <div class="box-tools">
                    <?= Html::create(['ajax-edit'], '创建', [
                        'data-toggle' => 'modal',
                        'data-target' => '#ajaxModal',
                    ]) ?>
                </div>
            </div>
            <div class="box-body table-responsive">
                <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel' => $searchModel,
                    // 重新定义分页样式
                    'tableOptions' => ['class' => 'table table-hover'],
                    'columns' => [
                        [
                            'class' => 'yii\grid\SerialColumn',
                        ],
                        'name',
                        [
                            'attribute' => 'cate.title',
                        ],
                        [
                            'attribute'=>'理由',
                            'format' => 'raw',
                            'value' => 'reason',
                        ],
                        [
                            'attribute' => 'type',
                            'value' => function($dataProvider) {
                                return $dataProvider->type == 1 ? '长假' : '短假';
                            }
                        ],
                        'starting_time',
                        'finish_time',
                        'report_time',

//                        [
//                            'attribute'=>'凭证',
//                            'format' => 'raw',
//                            'value' => function($model){
//                                return Html::img($model->certificate,['width'=>'80px']);
//                            }
//                        ],
                        [
                            'attribute' => '状态',
                            'value' => function($dataProvider) {
                                if($dataProvider->report_time){
                                    return '已完成';
                                }elseif($dataProvider->finish_time <= date('Y-m-d H:i:s')){
                                    return '延迟';
                                }elseif ($dataProvider->report_time == null){
                                    return '进行中 ';
                                }
                                //return $dataProvider->finish_time <= date('Y-m-d H:i:s') ? '延迟' : '进行中';
                            }
                        ],
                        [
                            'header' => "操作",
                            'class' => 'yii\grid\ActionColumn',
                            'template' => '{ajax-edit} {status} {destroy}{see}{recharge}',
                            'buttons' => [
                                'ajax-edit' => function ($url, $model, $key) {
                                    return Html::edit(['ajax-edit', 'id' => $model->id], '编辑', [
                                        'data-toggle' => 'modal',
                                        'data-target' => '#ajaxModal',
                                    ]);
                                },
                                'status' => function ($url, $model, $key) {
                                    return Html::status($model->status);
                                },
                                'destroy' => function ($url, $model, $key) {
                                    return Html::delete(['destroy', 'id' => $model->id]);
                                },
                                //销假
                                'see' => function ($url, $model, $key) {
                                    return Html::linkButton(['leave/leave','id' => $model->id], '销假', [

                                    ]);
                                },

                            ],
                        ],
                    ],
                ]); ?>
            </div>
        </div>
    </div>
    <script>
        //单项删除确认框
        function see(url,message){
            message = message?message:'你确定要删除这条数据吗？';
            art.dialog({
                title: '确认删除',
                okValue:'确认',
                cancelValue:'取消',
                width: 230,
                height: 100,
                fixed: true,
                content: message,
                ok: function () {
                    window.location.href=url;
                    return true;
                },
                cancel: function () {
                    return true;
                },
            });
        }
    </script>
